import homeApi from '@/api/model/home'
import router from '@/router'

// 消息 点击跳转页面
export const clickNews = (row) => {
  let ids = row.id + ''
  homeApi.myNews.changeNewsStatus.post({ id: ids })
  // type  通知类型
  let toDetailType = [1, 2, 3, 4, 5, 6, 7, 10]
  let toListType = [8, 9, 11]
  // operationType 1报价 2合同 3生产 4送货 5回款 6回款计划 7跟踪记录 8报销 9借款 10客户 11日程 12考勤打卡  13请假 14补卡 	15付款 16退款 22请购 23采购 24退货  25生产退货
  if (toDetailType.includes(row.type)) {
    handleClick(row.operationType, row.corrlelationId)
  }

  if (toListType.includes(row.type)) {
    switch (row.type) {
      case 8:
        router.push({
          path: '/home/mySchedule',
        })
        break
      case 11:
        router.push({
          path: '/home/myExamine',
        })
        break
    }
  }
}

// 我的申请 我的审批 点击跳转页面
export const handleClick = (type, corrlelationId) => {
  switch (type) {
    case 1:
      router.push({
        path: '/customer/quoteManagement/quoteDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 2:
      router.push({
        path: '/contract/contractManagement/contractDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 3:
      router.push({
        path: '/produce/produceOrderManagement/produceOrderDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 4:
      router.push({
        path: '/produce/deliverManagement/deliverDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 5:
      router.push({
        path: '/finance/collectManagement/collectDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 8:
      router.push({
        path: '/finance/reimburseManagement/reimburseDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 9:
      router.push({
        path: '/finance/loanManagement/loanDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 10:
      router.push({
        path: '/customer/customerManagement/customerDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 13:
      // router.push({
      //   path: '/finance/payment/paymentDetail',
      //   query: {
      //     id: corrlelationId
      //   }
      // })
      break
    case 15:
      router.push({
        path: '/finance/payment/paymentDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 16:
      router.push({
        path: '/produce/refund/refundDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 22:
      router.push({
        path: '/goods/purchaseRequest/purchaseRequestDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 23:
      router.push({
        path: '/goods/purchaseManagement/purchaseDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 24:
      router.push({
        path: '/goods/returnGoods/returnGoodsDetail',
        query: {
          id: corrlelationId
        }
      })
      break
    case 25:
      router.push({
        path: "/produce/returnProduct/returnProductDetail",
        query: {
          id: corrlelationId
        }
      })
      break
    case 27:
      router.push({
        path: "/contract/changeManagement/changeDetail",
        query: {
          id: corrlelationId
        }
      })
      break
  }
}


// 我的申请 我的审批  我的抄送  标题和摘要处理
export const initTableRow = (data) => {
  // streamType 1报价 2合同 3生产 4送货 5回款 6回款计划 7跟踪记录 8报销 9借款 10客户 11日程 12考勤打卡  13请假 14补卡 15付款 16退款 22请购 23采购 24退货 25生产退货
  let tableData = data
  tableData.forEach(item => {
    item.applyName = item.applicantName || item.detail.username || item.detail.adminName
    if (!item.detail) return
    // item.status = item.detail.status
    item.detail.streamType = item.streamType
    item.createTime = item.detail.createTime
    switch (item.streamType) {
      case 1:
        item.title = item.detail.quotesName
        item.detail.streamTypeName = '报价'
        break
      case 2:
        item.title = item.detail.name
        item.detail.streamTypeName = '合同'
        break
      case 3:
        item.title = item.detail.name
        item.detail.streamTypeName = '生产'
        this.produceStatus.forEach(p_item => {
          if (p_item.value == item.detail.type) {
            item.detail.typeName = p_item.name
          }
        })

        break
      case 4:
        item.title = item.detail.name
        item.detail.streamTypeName = '送货'
        this.deliverStatus.forEach(p_item => {
          if (p_item.value == item.detail.type) {
            item.detail.typeName = p_item.name
          }
        })
        break
      case 5:
        item.title = item.detail.paymentName
        item.detail.streamTypeName = '收款'
        break
      case 7:
        item.title = item.detail.followName
        item.detail.streamTypeName = '跟踪记录'
        this.followType.forEach(p_item => {
          if (p_item.value == item.detail.type) {
            item.detail.typeName = p_item.name
          }
        })
        break
      case 8:
        item.title = item.detail.reimbursementName
        item.detail.streamTypeName = '报销'
        break
      case 9:
        // item.title = item.detail.loanName
        item.detail.streamTypeName = '借款'
        break
      case 10:
        item.title = item.detail.customerName
        item.detail.streamTypeName = '客户'
        break
      case 13:
        // item.title = item.title
        item.detail.streamTypeName = '请假'
        break
      case 15:
        item.title = item.detail.title
        item.detail.streamTypeName = '付款'
        break
      case 16:
        item.title = item.detail.title
        item.detail.streamTypeName = '退款'
        break
      case 22:
        item.title = item.detail.title
        item.detail.streamTypeName = '请购'
        break

      case 23:
        item.title = item.detail.title
        item.detail.streamTypeName = '采购'
        break
      case 24:
        item.title = item.detail.title
        item.detail.streamTypeName = '退货'
        break
      case 25:
        item.title = item.detail.name
        item.detail.streamTypeName = '生产退货'
        break
      case 27:
        item.title = item.detail.name
        item.detail.streamTypeName = '合同变更'
        break
    }
  })

}